﻿using NUnit.Framework;
using mmsquare.dotNet.TestHelper.Tests.TestCases;
using mmsquare.dotNet.TestHelper;

namespace mmsquare.dotNet.TestHelper.Tests
{
    [TestFixture]
    public class SimpleSerialisationTests
    {

        [Test]
        public void Should_Serialise_Simple_Object_With_Only_String_Properties()
        {

            var p = new Person()
            {
                FirstName = "Jon",
                LastName = "Skeet"
            };

            string s = InitialiserFromInstance.Create(p);

            Assert.That(s, Is.EqualTo(@"var o = new Person { FirstName = ""Jon"", LastName = ""Skeet"" };"));
        }

        [Test]
        public void Should_Serialise_Simple_Object_With_Only_Set_String_Properties()
        {

            var p = new Person()
            {
                FirstName = "Jon",
            };

            string s = InitialiserFromInstance.Create(p);

            Assert.That(s, Is.EqualTo(@"var o = new Person { FirstName = ""Jon"" };"));
        }

        [Test]
        public void Should_Serialise_Simple_Object_With_Empty_String_Properties()
        {

            var p = new Person()
            {
                FirstName = "Jon",
                LastName = string.Empty,
            };

            string s = InitialiserFromInstance.Create(p);

            Assert.That(s, Is.EqualTo(@"var o = new Person { FirstName = ""Jon"", LastName = string.Empty };"));
        }


        [Test]
        public void Should_Serialise_Nested_Objects()
        {
            var pwc = new PersonWithACar
            {
                Person = new Person { LastName = "Tester" },
                Car = new Car { Year = 2009 }
            };

            string s = InitialiserFromInstance.Create(pwc);

            Assert.That(s, Is.EqualTo("var o = new PersonWithACar { Person = new Person { LastName = \"Tester\" }, Car = new Car { Year = 2009 } };"));


        }
    }
}
